<html>
<meta http-equiv="Content-Type" content="text/html;charset=windows-1252" >
<head>
<script src="isaac.js" type="text/javascript"></script>
<script src="bCrypt.js" type="text/javascript"></script>

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://code.jquery.com/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
var id;
var bcrypt = new bCrypt();
function enable(){
	if(bcrypt.ready()){
		$("#submit").removeAttr("disabled");
		$("#submit").attr("value","Generate Hash");
		clearInterval(id);
	}
}
$(document).ready(function(){
	 id = setInterval(enable,250);
	 $("#progressbar").progressbar({ value: 0 });
 });

var begin = '';
function result(hash){
    	$("#hash").val(hash);
	$("#progressbar").progressbar({ value: 100 });
}

function crypt(){
	var salt;
	if($("#salt").val().length != 0){
		salt = $("#salt").val();
	}else{
		try{
                	salt = bcrypt.gensalt($("#rounds").val());
		}catch(err){
                	alert(err);
                	return;
		}
		$("#salt").val(salt);
	}
        try{
           	$("#progressbar").progressbar({ value: 0 });
		bcrypt.hashpw($("#password").val(), $("#salt").val(), result, function() {
                	var value = $('#progressbar').progressbar( "option", "value" );
                    	$('#progressbar').progressbar({ value: value + 1 });
                });
        }catch(err){
                alert(err);
                return;
        }
}
</script>
<style type="text/css">
    #progressbar {
        width: 400px;
    }
</style
</head>
<body>
<form >
<label for="password">Password: </label><input size=30 type="text" name="password" id="password"></input>
<br />
<label for="salt">Salt (Optional): </label><input size=30 type="text" name="salt" id="salt"></input>
<br />
<label for="rounds">Rounds: </label>
<select id="rounds" name="rounds">
  <option value=5>5</option>
  <option value=6>6</option>
  <option value=7>7</option>
  <option value=8>8</option>
  <option value=9>9</option>
  <option value=10>10</option>
  <option value=11>11</option>
  <option value=12>12</option>
</select>
<br />
<INPUT TYPE="button" NAME="button" value="Waiting for PRNG..." onClick="crypt()" id="submit"/>
<br />
<br />
<label for="hash">Hash: </label><input size=60 type="text" name="hash" id="hash" READONLY></input>
</form>
<div id="progressbar"></div>
</body>
</html>
